home *** CD-ROM | disk | FTP | other *** search
/ Network Supervisor's Toolkit / Network Supervisor's Toolkit.iso / tools / nwtp06 / s_pep.pas < prev    next >
Pascal/Delphi Source File  |  1996-07-10  |  3KB  |  126 lines

  1. {$X+,V-,B-}
  2. program S_PEP;
  3.  
  4. { Testprogram for the nwPEP unit / NwTP 0.6 API. (c) 1993,1995, R.Spronk }
  5.  
  6. uses crt,nwMisc,nwIPX,nwPEP; { Listener/ Slave }
  7.  
  8. { Listen for incoming packet.. sent acknowledgement of receipt }
  9.  
  10. { Note that the acknowledgement is done automatically by the receiving ESR }
  11.  
  12. CONST IOSocket=$5678;
  13.  
  14. Var ListenECB    :Tecb;
  15.     ListenPepHdr     :TpepHeader;
  16.  
  17.     SendECB       :Tecb;
  18.     SendPepHdr    :TpepHeader;
  19.  
  20.     socket        :word;
  21.     buf           :array[1..546] of byte;
  22.     t             :byte;
  23.     ReceivedBufLen:word;
  24.     PacketReceived:boolean;
  25.  
  26.     NewStack:array[1..1024] of word;  { !! used by ESR }
  27.     StackBottom:word;                 { !! used by ESR }
  28.  
  29.  
  30.  
  31. {$F+}
  32. Procedure ListenAndAckHandler(Var p:TPecb);
  33. begin
  34. If (ListenECB.CompletionCode<>0)        
  35.  or (ListenPepHdr.IPXhdr.packetType<>PEP_PACKET_TYPE) 
  36.  or (ListenPepHdr.clienttype<>$EA)
  37.   then IPXlistenForPacket(ListenECB)
  38.   else begin
  39.        PacketReceived:=true;
  40.        ListenPepHdr.IPXhdr.source.socket:=swap(ListenPepHdr.IPXhdr.source.socket);
  41.        { socket is hi-lo in IPX/PEPHeaders. SetupSendECB expects lo-hi }
  42.        PEPsetupSendECB(NIL,IOsocket,ListenPepHdr.IPXhdr.source,@buf,0,
  43.                        SendPepHdr,SendECB);
  44.        SendPepHdr.TransactionId:=ListenPepHdr.TransactionId;
  45.        SendPepHdr.clientType:=$EA;
  46.        IPXsendPacket(SendECB);
  47.        end;
  48. end;
  49. {$F-}
  50.  
  51. {$F+}
  52. Procedure ListenAndAckESR; assembler;
  53. asm { ES:SI are the only valid registers when entering this procedure ! }
  54.     mov dx, seg stackbottom
  55.     mov ds, dx
  56.  
  57.     mov dx,ss  { setup of a new local stack }
  58.     mov bx,sp  { ss:sp copied to dx:bx}
  59.     mov ax,ds
  60.     mov ss,ax
  61.     mov sp,offset stackbottom
  62.     push dx    { push old ss:sp on new stack }
  63.     push bx
  64.  
  65.     push es    { push es:si on stack as local vars }
  66.     push si
  67.     mov  di,sp
  68.  
  69.     push ss    { push address of local ptr on stack }
  70.     push di
  71.     CALL ListenAndAckHandler
  72.  
  73.     add sp,4   { skip stack ptr-copy }
  74.     pop bx     { restore ss:sp from new stack }
  75.     pop dx
  76.     mov sp,bx
  77.     mov ss,dx
  78. end;
  79. {$F-}
  80.  
  81.  
  82. Var dest:TinternetworkAddress;
  83.     ticks,ticks2:word;
  84.  
  85. begin
  86. IF NOT IpxInitialize
  87.  then begin
  88.       writeln('Ipx needs to be installed.');
  89.       halt(1);
  90.       end;
  91. socket:=IOSocket;
  92. IF NOT IPXopenSocket(Socket,SHORT_LIVED_SOCKET)
  93.  then begin
  94.       writeln('IPXopenSocket returned error# ',nwIPX.result);
  95.       halt(1);
  96.       end;
  97.  
  98. { listen for incoming pep-packet }
  99.  
  100. PacketReceived:=False;
  101. { Empty receive buffer (ListenECB.fragment[2].address^) }
  102. FillChar(buf,546,#0);
  103.  
  104. { Setup ECB and IPX header }
  105. PEPSetupListenECB(Addr(ListenAndAckESR),IOsocket,@buf,546,
  106.                   ListenPepHdr,ListenECB);
  107.  
  108. IPXListenForPacket(ListenECB);
  109. writeln('Listening for incoming packet.');
  110.  
  111. IPXGetIntervalMarker(ticks);
  112. REPEAT
  113.  IPXrelinquishControl;
  114.  IPXGetIntervalMarker(ticks2)
  115. UNTIL PacketReceived or ((ticks2-ticks)>(30*18));
  116.  
  117. { do something with received buffer }
  118. IF PacketReceived
  119.  then writeln('Packet received and acknowledged.')
  120.  else writeln('Timeout: no packet received in 30 seconds.');
  121.  
  122. IF NOT IPXcloseSocket(IOsocket)
  123.  then writeln('IPXcloseSocket returned error# ',nwIPX.result);
  124.  
  125. end.
  126.